package com.liu.nb.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.liu.nb.entity.DebugtaskPole;
import com.liu.nb.entity.Receiptdebug;
import com.liu.nb.util.Result;
import com.sun.javafx.collections.MappingChange;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 消缺任务和塔杆中间表 前端控制器
 * </p>
 *
 * @author liuziyi
 * @since 2021-08-31
 */
@RestController
@RequestMapping("/nb/debugtask-pole")
public class DebugtaskPoleController extends BaseController{

    /**
     * 查看消缺任务情况和回执
     * @param id
     * @return
     */
    @PreAuthorize("hasAnyRole('xianluadmin','xiaoqueyuan')")
    @PostMapping("/getOneDeBugTask")
    public Result getOneDeBugTask(String id){
        Receiptdebug receiptdeBug = receiptdebugService.getOne(new QueryWrapper<Receiptdebug>()
                .eq("did", id));
        List<DebugtaskPole> oneDeBugTaskAll = debugtaskPoleService.getOneDeBugTaskAll(id);
        DebugtaskPole debugtaskPole = debugtaskPoleService.getOneDeBugTask(id);
        Map<String,Object> oneDeBugTaskMap = new HashMap<>();
        oneDeBugTaskMap.put("oneTask",debugtaskPole);
        oneDeBugTaskMap.put("oneTaskAll",oneDeBugTaskAll);
        oneDeBugTaskMap.put("receiptdeBug",receiptdeBug);
        return Result.success(oneDeBugTaskMap);
    }


    /**
     * 任务统计
     * @param id
     * @param cid
     * @param state
     * @param firstTime
     * @param lastTime
     * @param current
     * @param size
     * @return
     */
    @PostMapping("/getPatrolTaskBug")
    public Result getPatrolTaskBug(String id, String cid, Integer state, LocalDateTime firstTime, LocalDateTime lastTime,Integer current,Integer size){
        Integer current2 = 1;
        Integer size2 = 5;
        if(current==null){
            current2 = current;
        }
        if(size==null){
            size2 = size;
        }

        Page<DebugtaskPole> page = new Page<>(current2,size2);
        IPage<DebugtaskPole> patrolTaskBugList = debugtaskPoleService.getPatrolTaskBug(page, id, cid, state, firstTime, lastTime);
        return Result.success(patrolTaskBugList);
    }



}
